package src.edu.wayne.cs.csc4110.hw6.implementations;

import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class VideoFrameImpl extends JFrame {
	
	/**
	 * Creates a frame work the user to interact with
	 */
	private static final long serialVersionUID = 8688451479290722667L;

	private static VideoFrameImpl videoFrame;

	private JPanel currentPanel;
	private boolean boolPanelSet = false;
	private static final Color frameColor = new Color(59,89,152);
	
	private VideoFrameImpl(){}

	public static synchronized VideoFrameImpl getVideoFrame() {
		
		if (videoFrame == null)
		{
			videoFrame = new VideoFrameImpl();
			videoFrame.setSize(600,480);
			videoFrame.setBackground(VideoFrameImpl.frameColor);
			videoFrame.setLocationRelativeTo(null); // Center the frame
			videoFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			videoFrame.setVisible(false);
		}
		return videoFrame;
	}

	public void setCurrentPanel(JPanel newPanel, String newTitle)
	{
		if (boolPanelSet == true)
		{
			videoFrame.setVisible(false);
			videoFrame.remove(currentPanel);
			boolPanelSet = false;
		}
		boolPanelSet = true;
		currentPanel = newPanel;
		videoFrame.add(newPanel);
		videoFrame.setTitle(newTitle);
		videoFrame.validate();
		videoFrame.setVisible(true);
		videoFrame.repaint();
	}
	
	public static Color getColor()
	{
		return VideoFrameImpl.frameColor;
	}
	
}
